<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>个人信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//unpkg.com/layui@2.9.21/dist/css/layui.css" rel="stylesheet">
</head>
<script>
    let userSession = sessionStorage.getItem("admin");
    if (userSession === null){
        window.location.href = "index.html";
    }
</script>
<body>
<div class="layui-layout layui-layout-admin">
    <script>
        var value = sessionStorage.getItem("admin");
        if (value ===null){
            alert("请先登录!")
            window.location.href = "../login/login.html"
        }
    </script>
    <div class="layui-header" style="background-color: #c0c4cc">
        <div class="layui-logo layui-hide-xs layui-bg-black">酒店预定管理系统</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                <a href="javascript:;">
                    <img src="//unpkg.com/outeres@0.0.10/img/layui/icon-v2.png" class="layui-nav-img">
                    <span id="head_user"></span>
                    <script>
                        var value = sessionStorage.getItem("name");
                        document.getElementById("head_user").textContent=value
                    </script>
                </a>
            </li>
            <!--            注释了右侧框-->
            <!--            <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>-->
            <!--                <a href="javascript:;">-->
            <!--                    <i class="layui-icon layui-icon-more-vertical"></i>-->
            <!--                </a>-->
            <!--            </li>-->
        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll" style="background-color:sandybrown;">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test" style="background-color:sandybrown">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">个人信息管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="person_information.html">个人信息</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">酒店订单管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="OrderList.html">预定房间订单</a></dd>
                        <dd><a href="checkinList.html">已入住房间订单</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">客房信息管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guestroom_list.html">客房列表</a></dd>
                        <dd><a href="roomType.html">房间类型</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">酒店活动管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="activity.html">活动管理</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">会员管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="member_management.html">会员列表</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <blockquote class="layui-elem-quote layui-text">
                <span class="layui-breadcrumb">
                  <a href="index.html">首页</a>
                    <a><cite>个人信息管理</cite></a>
                    <a><cite>个人信息</cite></a>
                </span>
            </blockquote>
            <!--                <div class="layui-card-header">-->

            <!--                </div>-->
            <div class="layui-card-body">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                    <legend>个人信息修改</legend>
                </fieldset>

                <div class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" id = "username" lay-verify="title" autocomplete="off" placeholder="请输入账号" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="userpass" id="userpass" placeholder="请输入密码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-block">
                            <input type="text" name="realname" id="realname" placeholder="请输入昵称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1" id="update_sumbit">立即提交</button>
                        </div>
                    </div>
                </div>
            </div>
            <br><br>
        </div>
    </div>
    <div class="layui-footer">
        <!-- 底部固定区域 -->
        个人信息管理页面
    </div>
</div>

<script src="//unpkg.com/layui@2.9.21/dist/layui.js"></script>
<script>
    //JS
    layui.use(['element', 'layer', 'util'], function(){
        var element = layui.element;
        var layer = layui.layer;
        var util = layui.util;
        var $ = layui.$;

        //头部事件
        util.event('lay-header-event', {
            menuLeft: function(othis){ // 左侧菜单事件
                layer.msg('展开左侧菜单的操作', {icon: 0});
            },
            menuRight: function(){  // 右侧菜单事件
                layer.open({
                    type: 1,
                    title: '更多',
                    content: '<div style="padding: 15px;">处理右侧面板的操作</div>',
                    area: ['260px', '100%'],
                    offset: 'rt', // 右上角
                    anim: 'slideLeft', // 从右侧抽屉滑出
                    shadeClose: true,
                    scrollbar: false
                });
            }
        });
    });
</script>
<script src="../jquery/jquery-3.6.0.js"></script>
<script>
    $("#update_sumbit").click(function (){
        const formData ={
            admin:Number(userSession),
            username:document.getElementById("username").value,
            userpass:document.getElementById("userpass").value,
            realname:document.getElementById("realname").value,
        }
        $.ajax({
            url:"/user/updateById",
            type:"post",
            cache:false,
            contentType:"application/json;charset=utf-8",
            data:JSON.stringify(formData),
            datatype: "json",
            success:function (response){
                console.log("返回: "+response);
                if (response.code ===200){
                    layer.msg("更新用户成功");
                }
            },
            error:function (response){
                console.log("出错返回: "+response);
            }
        });
    })
</script>
<script>
    // 这里是个人信息添加
    let JSON_userImage = {};
    $.ajax({
        url:"/user/selectById",
        type:"post",
        cache:false,
        datatype:"json",
        contentType:"application/json;charset=utf-8",
        data:JSON.stringify({
            userId: Number(userSession)
        }),
        success:function (response){
            console.log("返回: "+response);
            if(response.code === 200) {
                // 把所有的部门数据，存放到json中
                JSON_userImage = response.data;
                $("#username").val(JSON_userImage.username);
                $("#userpass").val(JSON_userImage.userpass);
                $("#realname").val(JSON_userImage.realname);
            }
        },
        error:function(response){
            console.log("出错返回: " + response);
        }
    });

</script>
</body>
</html>